package database

import (
	"obsidian-plugin-server/config"
	"obsidian-plugin-server/models"

	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
)

func InitDB(cfg *config.Config) (*gorm.DB, error) {
	return gorm.Open(sqlite.Open(cfg.Database.Path), &gorm.Config{})
}

func AutoMigrate(db *gorm.DB) error {
	return db.AutoMigrate(
		&models.User{},
		&models.Document{},
		&models.ApiTokenLog{},
		&models.AppConfig{},
	)
}
